package com.zxtc.wh.servlet;


import com.google.gson.Gson;
import com.zxtc.wh.dao.UserInofDaoImpl;
import com.zxtc.wh.pojo.Result;
import com.zxtc.wh.pojo.UserInofPojo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/getUserInofPojos")
public class GetUserInofPojos extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");

//        super.doGet(req, resp);
        GetUserInofPojosResult result = new GetUserInofPojosResult();

        try {
            List<UserInofPojo> userInofPojos = new UserInofDaoImpl().getUserInofPojos();
            result.data = userInofPojos;
            result.responseCode = 200;
            result.message = "ok";


        } catch (SQLException | ClassNotFoundException e) {
            e.printStackTrace();

            result.responseCode = 400;
            result.message = e.toString();
        }


        Gson gson = new Gson();
        String json = gson.toJson(result);
        resp.getWriter().println(json);
    }

    private class GetUserInofPojosResult extends Result<List<UserInofPojo>> {
    }
}
